package com.yuqing.sentimentapp.home.presenter.impl;

import com.yuqing.sentimentapp.base.BaseObserver;
import com.yuqing.sentimentapp.home.acitivity.SpecialTopicDetailActivity;
import com.yuqing.sentimentapp.home.bean.RecommendDataBean;
import com.yuqing.sentimentapp.home.bean.SpecialTopicDetailDataBean;
import com.yuqing.sentimentapp.home.fragment.RecommendFragment;
import com.yuqing.sentimentapp.home.presenter.SpecialTopicDetailPresenter;
import com.yuqing.sentimentapp.module.ModuleManager;
import com.yuqing.sentimentapp.yqlist.bean.YqListResultBean;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by ShenHe on 2019/3/14.
 */

public class SpecialTopicDetailPresenterImpl implements SpecialTopicDetailPresenter {
    private SpecialTopicDetailActivity activity;

    public SpecialTopicDetailPresenterImpl(SpecialTopicDetailActivity activity) {
        this.activity = activity;
    }

    @Override
    public void loadSpecialTopicDetailRequest(String topicId) {
        ModuleManager.getInstance().getSpecialTopicDetailResult(activity, topicId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<SpecialTopicDetailDataBean>() {
                    @Override
                    protected void hideDialog() {
                        activity.stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        activity.startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(SpecialTopicDetailDataBean yqListResultBean) {
                        if (checkContext()) return;
                        activity.returnSpecialTopicDetaiResult(yqListResultBean);
                    }

                    @Override
                    protected void onFailure(String message) {
                        activity.onFailure(message);
                    }
                });
    }

    private boolean checkContext() {
        if (activity == null || activity.isFinishing() || activity.isDestroyed())
            return true;
        return false;
    }
}
